/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.sx.sx1.lintcode.day717.test;

import java.io.File;

//删除目录
//https://blog.51cto.com/u_16175487/7490280
public class DeleteDirectoryExample {

    private static void deleteDirectoryContents(File directory) {
        File[] files = directory.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    deleteDirectoryContents(file);
                }
                file.delete();
            }
        }
    }

    private static void deleteDirectory(File directory) {
        deleteDirectoryContents(directory);
        directory.delete();
    }

    public static void main(String[] args) {
        String directoryPath = "H:\\ws\\abcd";
        File directory = new File(directoryPath);
        deleteDirectory(directory);
    }
}
